package monster.com.cvh.activity;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import monster.com.cvh.R;
import monster.com.cvh.activity.base.PermissionActivity;
import monster.com.cvh.fragment.MessageFragment;
import monster.com.cvh.fragment.NoticeFragment;
import monster.com.cvh.util.StatusBarUtil;

/**
 * Created by ASUS on 2018/3/13.
 * 消息提醒界面
 */

public class MessageNoticeActivity extends PermissionActivity {
    @BindView(R.id.iv_activity_message_notice_back)
    ImageView mIvActivityMessageNoticeBack;
    @BindView(R.id.tb_activity_message_notice)
    SlidingTabLayout mTbActivityMessageNotice;
    @BindView(R.id.vp_activity_message_notice)
    ViewPager mVpActivityMessageNotice;
    private String[] mTitles = {"消息","通知"};
    private List<Fragment> mFragments = new ArrayList<>();
    private MyViewPagerAdapter adapter;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_message_notice;
    }

    @Override
    protected void initEvent() {
    }

    @Override
    protected void initData() {

        //修改状态栏颜色
        StatusBarUtil.setStatusBarLightMode(MessageNoticeActivity.this, Color.WHITE);
        mFragments.add(new MessageFragment());
        mFragments.add(new NoticeFragment());
        adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        mVpActivityMessageNotice.setAdapter(adapter);
        mTbActivityMessageNotice.setViewPager(mVpActivityMessageNotice);

    }



    @Override
    protected void onResume() {
        super.onResume();
        int id = getIntent().getIntExtra("id",0);
        if(id ==2){
            mVpActivityMessageNotice.setCurrentItem(1);
        }
    }

    /**
     * 后退按钮
     */
    @OnClick(R.id.iv_activity_message_notice_back)
    public void onViewClicked() {
        finish();
    }


    private class MyViewPagerAdapter extends FragmentStatePagerAdapter {

        public MyViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }
    }
}
